package io;

import java.io.*;
import java.text.BreakIterator;
import java.util.Scanner;

//在流连接中使用PrintWriter
public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException, UnsupportedEncodingException {
        //向PW2。txt中写入
       /* FileOutputStream fos=new FileOutputStream("pw.txt",true);
        OutputStreamWriter osw=new OutputStreamWriter(fos);
        BufferedWriter bw=new BufferedWriter(osw);
        PrintWriter pw=new PrintWriter("pw2.txt","UTF-8");
        pw.println("你好你好你好");
        System.out.println("写入完毕");
        pw.close();*/


        /*记事本功能 控制台输入每一行字符串按行写入到文件中 单独输入exit 程序退出*/
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入新的记事本");
        String line = sc.nextLine();
        FileOutputStream fos = new FileOutputStream("pw01.txt", true);
        OutputStreamWriter osw = new OutputStreamWriter(fos);
        BufferedWriter bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);
        while (true) {
            if (line.equals("exit")) {
                System.out.println("退出");
                break;
            }
            pw.println(line);
            System.out.println("请输入");
            line = sc.nextLine();
            pw.flush();
        }
        pw.close();
    }
}